'use strict';
const db = uniCloud.database()
exports.main = async (event, context) => {
	//event为客户端上传的参数
	const {	loginName,password,phone,vCode,type} = event
	const {affectedDocs,data} = await db.collection('user').aggregate()
	.match(type === 'account'?{loginName,password}:{phone})
	.end()
	// console.log('event : ', event)
	
	//返回数据给客户端
	return affectedDocs ? {
		code: 200,
		msg: "登陆成功",
		data: data[0]
	} : {
		code:0,
		msg: type === 'account'? '登录失败，请检查用户名和密码': '手机号未注册',
		data: []
	}
};
